<?php

class StatisticsSaveLogAction extends SzAbstractAction
{
    protected $paramTypes = array(
        SzAbstractAction::TYPE_INT,
        SzAbstractAction::TYPE_STRING,
        SzAbstractAction::TYPE_ARRAY,
    );

    /**
     * Statistics Save Log
     *
     * @param int $userId
     * @param string $act
     * @param array $logData
     * @return SzResponse
     */
    public function execute($userId, $act, $logData)
    {
        $clientData = [
            'tid' => isset($logData[0]) ? $logData[0] : '',
            'item' => isset($logData[1]) ? $logData[1] : '',
            'value' => isset($logData[2]) ? $logData[2] : 1,
            'value2' => isset($logData[3]) ? $logData[3] : 0,
        ];
        $clientData['value']    = empty($clientData['value']) ? 0 : (int)$clientData['value'];
        $clientData['value2']   = empty($clientData['value']) ? 0 : (int)$clientData['value2'];

        return $this->buildResponse(
            StatisticsService::get()->saveLog($userId, $act, array('clientData' => $clientData))
        );
    }

}